package com.cc.utils.message;

import com.cc.utils.DBUtil;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.Date;

/**
 * Created by Administrator on 2017/5/10.
 */
public class SaveMessage {
    public static void SaveMessage(String message) {
        //存入数据库中
        Connection conn = null;
        PreparedStatement pst = null;
        try {
            //创建数据库链接
            conn = DBUtil.getConnection();
            //创建预处理器
            pst = conn.prepareStatement("insert into test(name,creat_time)values(?,?)");
            pst.setString(1, message);
            long now = new Date().getTime();
            pst.setTimestamp(2, new java.sql.Timestamp(now));
            pst.execute();
        } catch (SQLException ex) {
            System.out.println("数据库操作异常：" + ex.getMessage());
        } finally {
            DBUtil.closeConnection(conn);
        }
    }
}
